package _1_proxy

import "fmt"
//抽象主题
type Subject interface {
	Do() string
}
//真实主题
type RealSubject struct {

}

func (self *RealSubject)Do() string {
	str := "真实业务逻辑"
	fmt.Println(str)
	return str
}

//代理
type Proxy struct {
	real RealSubject
}

func (self *Proxy)Do()  string{
	//通过代理类可以在调用真实主题前后添加逻辑
	self.preRequest()
	do := self.real.Do()
	self.postRequest()
	return do
}
func (self *Proxy)preRequest()  {
	fmt.Println("代理前调用逻辑")
}
func (self *Proxy)postRequest()  {
	fmt.Println("代理后调用逻辑")
}
